#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<assert.h>
using namespace std;


namespace My
{
	class string
	{
	public:

		string(const char* str = "")
			:_size(strlen(str))
			,_capacity(_size)
		{
			_str = new char[_size + 1];
			strcpy(_str, str);
		}

		string(const string& s)
			:_size(s._size)
			, _capacity(s._capacity)
		{
			_str = new char[_capacity + 1];
			strcpy(_str, s._str);
		}


		string& operator=(const string& s)
		{
			if (this != &s)
			{
				string tmp(s);
				string::swap(tmp);
			}

			return *this;
		}

		void swap(string& s)
		{
			std::swap(_str, s._str);
			std::swap(_size, s._size);
			std::swap(_capacity, s._capacity);
		}

		~string()
		{
			delete[] _str;
			_size = 0;
			_capacity = 0;
		}

	private:

		char* _str;
		size_t _size;
		size_t _capacity;
	};


	void test01()
	{

		string s1;
		string s2("asdasd");
		s1 = s2;

		int i = 0;
	}
}

